//
//  FDMBroadcastLIstCollectionViewCell.m
//  Entertainment
//
//  Created by dllo on 16/4/21.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "FDMBroadcastLIstCollectionViewCell.h"
#import "FDMBroadrectTopRadioListModel.h"

@interface FDMBroadcastLIstCollectionViewCell ()

@property (nonatomic, retain) FDMBaseLabel *titleLabel;
@property (nonatomic, retain) UIImageView *titleImage;
@property (nonatomic, retain) FDMBaseLabel *radioPlayCount;
@property (nonatomic, retain) UIImageView *radioPlayView;
@property (nonatomic, retain) UIImageView *playImage;

@end
@implementation FDMBroadcastLIstCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.titleLabel = [[FDMBaseLabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        [self.titleLabel release];
        self.radioPlayCount = [[FDMBaseLabel alloc] init];
        [self.contentView addSubview:self.radioPlayCount];
        [self.radioPlayCount release];
        self.titleImage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.titleImage];
        [self.titleImage release];
        self.radioPlayView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.radioPlayView];
        [self.radioPlayView release];
        self.playImage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.playImage];
        [self.playImage release];
        
    }
    return self;
}

- (void)dealloc {
    [self.titleLabel release];
    [self.radioPlayCount release];
    [self.titleImage release];
    [self.radioPlayView release];
    [self.playImage release];
    [self.topRadioModel release];
    [super dealloc];
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    self.radioPlayView.image = [UIImage imageNamed:@"sound_playtimes@3x.png"];
    self.playImage.image = [UIImage imageNamed:@"icon_rec_bgm_preview@2x.png"];
    
    [self.titleImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(0);
        make.left.equalTo(self.contentView.mas_left);
        make.bottom.equalTo(self.contentView.mas_bottom);
        make.width.mas_equalTo(@100);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(10);
        make.left.equalTo(self.titleImage.mas_right).with.offset(10);
        make.height.mas_equalTo(@20);
        make.width.mas_equalTo(@(CONTENTVIEW_WIDTH - 110));
    }];
    [self.playImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).with.offset(10);
        make.left.equalTo(self.contentView.mas_right).with.offset(-50);
        make.right.equalTo(self.contentView.mas_right).with.offset(-10);
        make.height.mas_equalTo(@40);
    }];
    [self.radioPlayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_bottom).with.offset(-30);
        make.left.equalTo(self.titleImage.mas_right).with.offset(10);
        make.width.mas_equalTo(@20);
        make.height.mas_equalTo(@20);
    }];
    [self.radioPlayCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_bottom).with.offset(-30);
        make.left.equalTo(self.titleImage.mas_right).with.offset(40);
        make.height.mas_equalTo(@20);
        make.width.mas_equalTo(@(CONTENTVIEW_WIDTH - 150));
    }];
}

- (void)setTopRadioModel:(FDMBroadrectTopRadioListModel *)topRadioModel {
    if (_topRadioModel != topRadioModel) {
        [_topRadioModel release];
        _topRadioModel = [topRadioModel retain];
        self.titleLabel.text = _topRadioModel.rname;
        [self.titleImage sd_setImageWithURL:[NSURL URLWithString:_topRadioModel.radioCoverSmall] placeholderImage:PLACEHOLDER_IMAGE];
        self.radioPlayCount.text = [_topRadioModel.radioPlayCount stringValue];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
